home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / exec / waitio.c < prev    next >
C/C++ Source or Header  |  1996-09-12  |  2KB  |  96 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: waitio.c,v 1.4 1996/08/13 13:56:09 digulla Exp $
  4.     $Log: waitio.c,v $
  5.     Revision 1.4  1996/08/13 13:56:09  digulla
  6.     Replaced __AROS_LA by __AROS_LHA
  7.     Replaced some __AROS_LH*I by __AROS_LH*
  8.     Sorted and added includes
  9.  
  10.     Revision 1.3  1996/08/01 17:41:22  digulla
  11.     Added standard header for all files
  12.  
  13.     Desc:
  14.     Lang: english
  15. */
  16. #include <exec/execbase.h>
  17. #include <exec/io.h>
  18. #include <aros/libcall.h>
  19.  
  20. /*****************************************************************************
  21.  
  22.     NAME */
  23.     #include <clib/exec_protos.h>
  24.  
  25.     __AROS_LH1(BYTE, WaitIO,
  26.  
  27. /*  SYNOPSIS */
  28.     __AROS_LHA(struct IORequest *, iORequest, A1),
  29.  
  30. /*  LOCATION */
  31.     struct ExecBase *, SysBase, 79, Exec)
  32.  
  33. /*  FUNCTION
  34.     Waits until the I/O request is completed and removes it from the
  35.     reply port. If the message is already done when calling this function
  36.     it doesn't wait but just remove the message.
  37.  
  38.     INPUTS
  39.     iORequest - Pointer to iorequest structure.
  40.  
  41.     RESULT
  42.     Error state of I/O request.
  43.  
  44.     NOTES
  45.  
  46.     EXAMPLE
  47.  
  48.     BUGS
  49.  
  50.     SEE ALSO
  51.     OpenDevice(), CloseDevice(), DoIO(), SendIO(), AbortIO(), CheckIO()
  52.  
  53.     INTERNALS
  54.  
  55.     HISTORY
  56.  
  57. ******************************************************************************/
  58. {
  59.     __AROS_FUNC_INIT
  60.  
  61.     /*
  62.     The I/O request is still in use if it wasn't done quick
  63.     and isn't yet replied (ln_Type==NT_MESSAGE).
  64.     If it is still in use wait until it is complete.
  65.     Note the the port may be used for other things as well - so
  66.     don't just wait but repeat the check.
  67.     */
  68.     while(!(iORequest->io_Flags&IOF_QUICK)&&
  69.       iORequest->io_Message.mn_Node.ln_Type==NT_MESSAGE)
  70.     /*
  71.         Wait at the reply port. Don't use WaitPort() - there may
  72.         already be other messages waiting at it.
  73.     */
  74.     Wait(1<<iORequest->io_Message.mn_ReplyPort->mp_SigBit);
  75.  
  76.     /*
  77.     If ln_Type is NT_REPLYMSG the I/O request must be removed from
  78.     the replyport's waiting queue.
  79.     */
  80.     if(iORequest->io_Message.mn_Node.ln_Type==NT_REPLYMSG)
  81.     {
  82.     /* Arbitrate for the message queue. */
  83.     Disable();
  84.  
  85.     /* Remove the message */
  86.     Remove(&iORequest->io_Message.mn_Node);
  87.     Enable();
  88.     }
  89.  
  90.     /* All done. Get returncode. */
  91.     return iORequest->io_Error;
  92.  
  93.     __AROS_FUNC_EXIT
  94. } /* WaitIO */
  95.  
  96.